package top.xiaoshuaila.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.xiaoshuaila.pojo.Admin;
import top.xiaoshuaila.pojo.RespBean;
import top.xiaoshuaila.pojo.Role;
import top.xiaoshuaila.service.IAdminService;
import top.xiaoshuaila.service.IRoleService;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小帅啦
 * @since 2021-05-01
 */
@RestController
@RequestMapping("/sytem/admin")
@Api(tags = "管理员接口")
public class AdminController {

    @Autowired
    private IAdminService adminService;
    @Autowired
    private IRoleService roleService;




    @ApiOperation("获取所有管理员")
    @GetMapping("/")
    public List<Admin> getAllAdmins(String keywords){
        return adminService.getAllAdmins(keywords);
    }

    @ApiOperation("更新操作员")
    @PostMapping
    public RespBean updateAdmin(@RequestBody Admin admin){
        if(adminService.updateById(admin))
            return RespBean.success("更新成功!");
        return RespBean.error("更新失败!");
    }
    @ApiOperation(("删除操作员"))
    @DeleteMapping
    public RespBean deleteAdmin(@RequestParam Integer id){
        if(adminService.removeById(id))
            return RespBean.success("删除成功!");
        return RespBean.error("删除失败!");
    }

    @ApiOperation("获取所有角色")
    @GetMapping("/roles")
    public List<Role>getAllRoles(){
        return roleService.list();
    }

    @ApiOperation("更新操作员角色")
    @PutMapping("/role")
    public RespBean updateAdminRole(Integer adminId,Integer[]rids){
        return adminService.updateAdminRole(adminId,rids);
    }

}
